package bishi.day38_6_28;

import java.util.Scanner;

/**
 * 红与黑
 *
 * @author 是阿秋啊
 * @date 2022/06/28 19:06
 **/
public class demo1 {
    static int ret = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int m = scanner.nextInt();
            int n = scanner.nextInt();
            boolean[][] dp = new boolean[m][n];
            int a = 0, b = 0;
            for (int i = 0; i < m; i++) {
                String s = scanner.next();
                for (int j = 0; j < n; j++) {
                    if ('.' == s.charAt(j)) {
                        dp[i][j] = true;
                    } else if ('#' == s.charAt(j)) {
                        dp[i][j] = false;
                    } else {
                        dp[i][j] = true;
                        a = i;
                        b = j;
                    }
                }
            }
            help(dp, a, b, m, n);
            System.out.println(ret);
            ret=0;
        }
    }

    private static void help(boolean[][] dp, int a, int b, int m, int n) {
        if (a >= m || b >= n || a < 0 || b < 0) {
            return;
        }
        if (!dp[a][b]) {
            return;
        }
        dp[a][b] = false;
        ret++;
        help(dp, a + 1, b, m, n);
        help(dp, a - 1, b, m, n);
        help(dp, a, b + 1, m, n);
        help(dp, a, b - 1, m, n);
    }
}